﻿using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using VIP.Data.EFProvider;
using VIP.Data.Entities;

namespace VIP.Data
{
    public static class DataExtensions
    {
        public static IServiceCollection AddVIPDbStore(this IServiceCollection services, string writeConnStr, string readOnlyConnStr)
        {
            //注册数据库上下文
            services.AddDbContext<VIPDbContext>(options =>
            {
                options.UseSqlServer(writeConnStr);
            }, ServiceLifetime.Scoped);
            services.AddDbContext<VIPDbReadOnlyContext>(options =>
            {
                options.UseSqlServer(readOnlyConnStr);
            }, ServiceLifetime.Scoped)
            .AddUnitOfWork<VIPDbContext, VIPDbReadOnlyContext>();
            return services;
        }
    }
}
